package com.renjibo.sharkerwave.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.renjibo.sharkerwave.R;
import com.renjibo.sharkerwave.models.Course;
import com.renjibo.sharkerwave.ui.activity.HomeDetailsActivity;

import java.util.ArrayList;
import java.util.List;

/**
 * 精选专辑的adapter
 * 任继波
 * Created by Administrator on 2017/4/10.
 */

public class GreatesAdapter extends RecyclerView.Adapter<GreatesAdapter.OneViewHolder> {

    private final LayoutInflater inflater;
    private Context context;
    private List<Course> topicCourse=new ArrayList<>();
    public GreatesAdapter(Context context,List<Course> topicCourse ) {
        inflater = LayoutInflater.from(context);
        this.context = context;
        this.topicCourse=topicCourse;
    }
    @Override
    public OneViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.greates_recycler_item_new, parent, false);
        return new OneViewHolder(view);
    }

    @Override
    public void onBindViewHolder(OneViewHolder holder, final int position) {
        final Course course = topicCourse.get(position);
        holder.greates_item__text_bottom.setText(course.speaker+"");
        holder.greates_item_text_title.setText(course.title+"");
        holder.greates_item_text_title2.setText(course.title2+"");
        if(course.type==1){
            Glide.with(context).load(R.drawable.home_image_small_video).centerCrop().into(holder.greates_item_image_small);
        }else{
            Glide
                    .with(context)
                    .load(R.drawable.home_image_small_video)
                    .centerCrop()
                    .placeholder(R.drawable.home_image_small_video)
                    .crossFade()
                    .into(holder.greates_item_image_small);
        }
        Glide.with(context).load(course.image).centerCrop().placeholder(R.drawable.bottom).crossFade().error(R.drawable.bottom).into(holder.greates_item_image_big);

        holder.view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                Toast.makeText(context, "条目跳转"+position, Toast.LENGTH_SHORT).show();
                Intent intent=new Intent(context, HomeDetailsActivity.class);
                intent.putExtra("object_id",course.object_id);
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return topicCourse.size();
    }

    class OneViewHolder extends RecyclerView.ViewHolder {
        View view;
        private final TextView greates_item__text_bottom;
        private final TextView greates_item_text_title2;
        private final TextView greates_item_text_title;
        private final ImageView greates_item_image_small;
        private final ImageView greates_item_image_big;

        public OneViewHolder(View itemView) {
            super(itemView);
            view = itemView;
            greates_item__text_bottom = (TextView) itemView.findViewById(R.id.greates_item__text_bottom);
            greates_item_text_title2 = (TextView) itemView.findViewById(R.id.greates_item_text_title2);
            greates_item_text_title = (TextView) itemView.findViewById(R.id.greates_item_text_title);
            greates_item_image_small = (ImageView) itemView.findViewById(R.id.greates_item_image_small);
            greates_item_image_big = (ImageView) itemView.findViewById(R.id.greates_item_image_big);
        }
    }
}
